<template>
	<!-- 培训经历 -->
	<view class="box">
		<!-- #ifdef MP-WEIXIN -->
		<view class="head"
			:style="'padding-top:'+statusBarHeight1+'px;padding-right:'+ (WXwidth + 15) +'px;height:' + (statusBarHeight1 + 44) + 'px'">
			<!-- #endif -->
			<!-- #ifndef MP-WEIXIN -->
			<view class="head"
				:style="'padding-top:'+(statusBarHeight1+10)+'px;height:' + (statusBarHeight1 + 54) + 'px'">
				<!-- #endif -->
				<image class="fanhui" @click="fanhui" src="https://pic.bangbangtongcheng.com/static/fanhui_bai.png"
					mode=""></image>
				<view class="centers">
					培训经历
				</view>
				<view class="head_right" @click="fanhui(1)">保存</view>
			</view>
			<!-- #ifdef MP-WEIXIN -->
			<view
				:style="'padding-top:'+statusBarHeight1+'px;height:' + (statusBarHeight1 + 44) + 'px;background-color: #64B6A8;'">
			</view>
			<!-- #endif -->
			<!-- #ifndef MP-WEIXIN -->
			<view
				:style="'padding-top:'+statusBarHeight1+'px;height:' + (statusBarHeight1 + 54) + 'px;background-color: #64B6A8;'">
			</view>
			<!-- #endif -->
			<view class="center">
				<view class="center_item">
					<view class="title">
						培训时间
					</view>
					<view class="neir">
						<picker style="flex:1;" mode="multiSelector" @change="dateChange1($event)" :value="dateIndex1" @columnchange="pickerColumnDept1" :range="workHours">
							<view class="inputs">{{dateEntry?dateEntry:'开始时间'}}</view>
						</picker>
						<view class="xian"></view>
						<picker style="flex:1;" mode="multiSelector" @change="dateChange2($event)" :value="dateIndex2" @columnchange="pickerColumnDept2" :range="workHours2">
							<view class="inputs">{{timeResignation?timeResignation:'结束时间'}}</view>
						</picker>
					</view>
				</view>
				<view class="center_item">
					<view class="title">
						培训机构
					</view>
					<view class="neir">
						<input class="inputs" v-model="data.trainingInstitutions" placeholder="培训机构名称" type="text">
					</view>
				</view>
				<view class="center_item">
					<view class="title">
						培训课程
					</view>
					<view class="neir">
						<input class="inputs" v-model="data.trainingCourse" placeholder="请填写培训课程" type="text">
					</view>
				</view>
			</view>
		</view>
</template>
<script>
	import permision from "@/js_sdk/wa-permission/permission.js"
	//#ifdef H5
	import wxshare from "@/utils/index.js";
	//#endif
	import {
		mapGetters
	} from "vuex";
	export default {
		data() {
			return {
				userInfo: uni.getStorageSync("Pduser"),
				WXwidth: '',
				data:{
					trainingTime:'',
					trainingInstitutions:'',
					trainingCourse:''
				},
				index:'',
				// 工作时间年，月
				workHours:[],
				workHours_month:[],
				workHours2:[],
				workHours2_month:[],
				dateIndex1:[0,0],
				dateIndex2:[0,0],
				pickerInitR1:0,
				pickerInitR2:0,
				dateEntry:'',
				timeResignation:'',
			};
		},
		onLoad(option) {
			var than = this;
			// 获取微信小程序胶囊和据右边宽度
			// #ifdef MP-WEIXIN
			// 获取胶囊信息
			let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
			let getWindowInfo = uni.getWindowInfo().screenWidth
			this.WXwidth = getWindowInfo - (menuButtonInfo.right - menuButtonInfo.width)
			// #endif
			this.getTime()
			if(option.index){
				this.index = option.index
				this.data = uni.getStorageSync('pxjl_key');
				this.dateEntry = this.data.trainingTime.split('|')[0]
				this.timeResignation = this.data.trainingTime.split('|')[1]
				uni.removeStorageSync('pxjl_key');
			}
			/* #ifdef H5 */
			this.jinzhi();
			/* #endif */
		},
		mounted() {
			
		},
		computed: {
			...mapGetters(["userid", "islogin", "statusBarHeight1", "userinfo"])
		},
		methods: {
			//获取当前日期
			getTime(){
				let myDate = new Date();
				const year = myDate.getFullYear()
				let month = myDate.getMonth() + 1
				let yearArr=[]
				let monthArr=[]
				for (var i = 1990; i <= year; i++) {
					yearArr.unshift(i)
					let j = i == year? month:'12'
					let months_arr=[]
					for (let s = 1; s <= j; s++) {
						months_arr.unshift(s)
					}
					monthArr.unshift(months_arr)
				}
				this.workHours.push(yearArr)
				this.workHours.push(monthArr[0])
				this.workHours_month = monthArr
				let yearArrs = JSON.parse(JSON.stringify(yearArr))
				let monthArrs = JSON.parse(JSON.stringify(monthArr))
				yearArrs.unshift('至今')
				monthArrs.unshift(['至今'])
				this.workHours2.push(yearArrs)
				this.workHours2.push(monthArrs[0])
				this.workHours2_month = monthArrs
			},
			pickerColumnDept1(e){
				if(e.detail.column == 0){
					let arr = []
					arr = this.workHours_month[e.detail.value]
					this.$set(this.workHours,1,arr)
					this.dateIndex1[0] = e.detail.value
					this.dateIndex1[1] = this.pickerInitR1
					let timern=setTimeout(()=>{
						this.dateIndex1[1] = 0
						clearTimeout(timern);
					},100) 
				}else{
					this.pickerInitR1=e.detail.value;
					this.dateIndex1[1]=e.detail.value;
				}
			},
			pickerColumnDept2(e){
				if(e.detail.column == 0){
					let arr = []
					arr = this.workHours2_month[e.detail.value]
					this.$set(this.workHours2,1,arr)
					this.dateIndex2[0] = e.detail.value
					this.dateIndex2[1] = this.pickerInitR2
					let timern=setTimeout(()=>{
						this.dateIndex2[1] = 0
						clearTimeout(timern);
					},100) 
				}else{
					this.pickerInitR2=e.detail.value;
					this.dateIndex2[1]=e.detail.value;
				}
			},
			dateChange1(e){
				if(this.timeResignation && this.timeResignation != '至今'){
					let year = this.timeResignation.split('.')[0]
					let month = this.timeResignation.split('.')[1]
					if(year < this.workHours[0][this.dateIndex1[0]]){
						uni.showToast({
							title: "开始时间不能大于结束时间",
							icon: "none",
							mask: true,
						});
						return
					}else if(year == this.workHours[0][this.dateIndex1[0]]){
						if(month<this.workHours[1][this.dateIndex1[1]]){
							uni.showToast({
								title: "开始职时间不能结束离职时间",
								icon: "none",
								mask: true,
							});
							return
						}
					}
				}
				this.dateIndex1 = e.target.value
				this.dateEntry = `${this.workHours[0][this.dateIndex1[0]]}.${this.workHours[1][this.dateIndex1[1]]}`
			},
			dateChange2(e){
				console.log(this.dateEntry,'数据')
				if(this.dateEntry){
					console.log(this.workHours2[0][this.dateIndex2[0]],'数据1223')
					if(this.workHours2[0][this.dateIndex2[0]] != '至今'){
						let year = this.dateEntry.split('.')[0]
						let month = this.dateEntry.split('.')[1]
						console.log(year,this.workHours2[0][this.dateIndex2[0]],'数据2')
						if(year > this.workHours2[0][this.dateIndex2[0]]){
							uni.showToast({
								title: "开始时间不能大于结束时间",
								icon: "none",
								mask: true,
							});
							return
						}else if(year == this.workHours2[0][this.dateIndex2[0]]){
							if(month>this.workHours2[1][this.dateIndex2[1]]){
								uni.showToast({
									title: "开始时间不能大于结束",
									icon: "none",
									mask: true,
								});
								return
							}
						}
					}
				}
				this.dateIndex2 = e.target.value
				if(this.workHours2[0][this.dateIndex2[0]] == '至今'){
					this.timeResignation = '至今'
				}else{
					this.timeResignation = `${this.workHours2[0][this.dateIndex2[0]]}.${this.workHours2[1][this.dateIndex2[1]]}`
				}
			},
			fanhui(index){
				if(index == '1'){
					if(this.data.trainingInstitutions == '' || this.data.trainingCourse == '' || this.timeResignation == '' || this.dateEntry == ''){
						uni.showToast({
							title: "请完善培训经历信息",
							icon: "none",
							mask: true,
						});
						return
					}
					this.data.trainingTime = this.dateEntry + '|' + this.timeResignation
					if(this.index){
						let pages = getCurrentPages();
						let prevPage = pages[ pages.length - 2 ];  
						this.$set(prevPage.$vm.trainExperience,this.index,this.data)
					}else{
						let pages = getCurrentPages();
						let prevPage = pages[ pages.length - 2 ];  
						prevPage.$vm.trainExperience.push(this.data)
					}   
				}
				uni.navigateBack({  
				    delta: 1
				});
			},
			jinzhi() {
				let _this = this;
				let param = window.location.href.split("#")[0];
				uni.request({
					method: "post",
					data: {
						url: param
					},
					header: {
						"content-type": "application/x-www-form-urlencoded",
					},
					url: "https://www.bangbangtongcheng.com/conven//mob/login/getJsTicket.do",
					success(re) {
						_this.jinzhifx(re.data);
					},
				});
			},
			jinzhifx(data) {
				wxshare.config({
					debug: false, //是否打开调试
					appId: data.appId, // 公众号的唯一标识
					timestamp: data.timestamp, // 生成签名的时间戳
			 	nonceStr: data.nonce, // ，生成签名的随机串
					signature: data.signature, // 签名
					jsApiList: ["hideMenuItems"],
				});
				// 禁止分享
				wxshare.hideMenuItems({
					// 要隐藏的菜单项，只能隐藏“传播类”和“保护类”按钮，所有menu项见附录3
					menuList: [
						"menuItem:share:appMessage",
						"menuItem:share:timeline",
						"menuItem:share:timeline",
						"menuItem:share:qq",
						"menuItem:favorite",
						"menuItem:share:QZone",
						"menuItem:openWithSafari",
					],
				});
			},
		},
	};
</script>
<style lang="less" scoped>
	.box {
		width: 100%;
		min-height: 100vh;
		background-color: #fff;
	}

	.head {
		position: fixed;
		top: 0;
		left: 0;
		width: 750rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 15px;
		background-color: #64B6A8;
		z-index: 1000;

		.fanhui {
			width: 40rpx;
			height: 40rpx;
		}

		.centers {
			font-size: 36rpx;
			font-weight: 400;
			color: #FFFFFF;
		}

		.head_right {
			font-size: 30rpx;
			font-weight: 400;
			color: #FFFFFF;
		}
	}
	.center{
		padding: 0 40rpx;
		.center_item{
			height: 190rpx;
			padding-top: 50rpx;
			.title{
				font-size: 26rpx;
				font-weight: 400;
				color: #333333;
			}
			.neir{
				width: 670rpx;
				height: 104rpx;
				display: flex;
				align-items: center;
				.inputs{
					flex: 1;
					height: 104rpx;
					border-bottom: 1px solid #e0e0e0;
					display: flex;
					align-items: center;
				}
				.xian{
					width: 36rpx;
					height: 1px;
					background-color: #333;
					margin: 0 20rpx;
				}
			}
		}
	}
</style>
